import random
print("计科1813 24 姜沭琪")

class Tortoise:
    def __init__(self):
        self.x = random.randint(0, 10)
        self.y = random.randint(0, 10)
        self.life = 100
        print('乌龟的初始位置是: (%d,%d)' % (self.x, self.y))
        print('生命值 : %d' % (self.life))

    def move(self):
        step = random.randint(1, 2)
        direction = random.randint(-1, 2)
        self.life -= step

        if direction == 2:
            if self.x + step - 10 == 1:
                self.x = 9
            elif self.x + step - 10 == 2:
                self.x = 8
            else:
                self.x += step

        if direction == 1:
            if self.y + step - 10 == 1:
                self.y = 9
            elif self.y + step - 10 == 2:
                self.y = 8
            else:
                self.y += step

        if direction == 0:
            if self.x - step == -1:
                self.x = 1
            elif self.x - step == -2:
                self.x = 2
            else:
                self.x -= step

        if direction == -1:
            if self.y - step == -1:
                self.y = 1
            elif self.y - step == -2:
                self.y = 2
            else:
                self.y -= step

        return (self.x, self.y)


class Fish:
    def __init__(self, name):
        self.name = name
        self.x = random.randint(0, 10)
        self.y = random.randint(0, 10)
        print('%s: (%d,%d)' % (name, self.x, self.y))

    def move(self):
        direction = random.randint(-1, 2)

        if direction == 2:
            if self.x + 1 - 10 == 1:
                self.x = 9
            else:
                self.x += 1

        if direction == 1:
            if self.y + 1 - 10 == 1:
                self.y = 9
            else:
                self.y += 1

        if direction == 0:
            if self.x - 1 == -1:
                self.x = 1
            else:
                self.x -= 1

        if direction == -1:
            if self.y - 1 == -1:
                self.y = 1
            else:
                self.y -= 1
        return (self.x, self.y)


def game():
    fishlist = list()
    fishObj = list()
    for i in range(1, 11):
        name = '小鱼' + str(i)
        fishlist.append(name)
    wugui = Tortoise()
    for fish in fishlist:
        fish = Fish(fish)
        fishObj.append(fish)

    while True:
        (x, y) = wugui.move()
        if wugui.life > 0:
            print('乌龟的位置: (%d,%d)' % (x, y))
        for fish in fishObj:
            (a, b) = fish.move()
            if (a, b) == (x, y) and wugui.life > 0:
                fishObj.remove(fish)
                print('%s被吃了' % (fish.name))
                print('被吃掉的小鱼的位置: (%d,%d)\n' %(a, b))
                if wugui.life > 80:
                    wugui.life = 100
                else:
                    wugui.life += 20
        if wugui.life == 0:
            print("乌龟没有体力了,游戏结束！")
            break
        elif fishObj == []:
            print('小鱼都被吃光啦！乌龟获得胜利！\n乌龟当前的体力为%d'%(wugui.life))
            break



    print('%d只鱼存活成功' % (len(fishObj)))



game()
